#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenu>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 1.创建菜单栏
    QMenuBar* menubar = new QMenuBar();
    this->setMenuWidget(menubar);

    // 2.创建菜单
    // 在文本后面加上&符号，表示快捷键
    QMenu* menu1 = new QMenu("文件(&F)");
    QMenu* menu2 = new QMenu("编辑(&E)");
    QMenu* menu3 = new QMenu("构建(&B)");
    QMenu* menu4 = new QMenu("调试(&D)");
    menubar->addMenu(menu1);
    menubar->addMenu(menu2);
    menubar->addMenu(menu3);
    menubar->addMenu(menu4);

    // 3.给菜单添加菜单项
    QAction* action1 = new QAction("新建");
    QAction* action2 = new QAction("打开");
    QAction* action3 = new QAction("保存");
    QAction* action4 = new QAction("退出");
    QAction* action5 = new QAction("菜单项2");
    QAction* action6 = new QAction("菜单项3");
    QAction* action7 = new QAction("菜单项4");
    menu1->addAction(action1);
    menu1->addAction(action2);
    menu1->addAction(action3);
    menu1->addAction(action4);
    menu2->addAction(action5);
    menu3->addAction(action6);
    menu4->addAction(action7);

    // 4.给菜单项添加操作
    // connect(点击哪里触发信号，触发什么信号，谁来触发信号，触发信号的效果)
    connect(action1,&QAction::triggered,this,&MainWindow::Create);
    connect(action4,&QAction::triggered,this,&MainWindow::Exit);
}

void MainWindow::Create()
{
    qDebug() << "创建文件";
}

void MainWindow::Exit()
{
    qDebug() << "退出";
}
MainWindow::~MainWindow()
{
    delete ui;
}

